'''
Created on 2011-11-5

@author: Administrator
'''
import os
import urllib2
import urllib
import urlparse
import webbrowser
class Chart():
    def __init__(self):
        self.cmdie='explorer '
        self.cmdfirefox='D:\\Mozilla Firefox\\firefox.exe '
#        os.system('explorer ')
#        c:\\360lowprice.html')
    def getchart_p(self,srcdata,srctitle):
        sum=0.0
        chd='t:' 
        chl='' 
        for src in srcdata:
            sum=sum+src[1]
            chl=chl+src[0]+'|'
        dstdata=[]
        
        for src in srcdata:
            dstdata.append(src[1]/sum*360)  
        for dst in dstdata:
            chd=chd+str(dst)+','
        
        urlpre='http://chart.apis.google.com/chart'
        
        p={}
        p['cht']='p3'
        p['chd']=chd.strip(',')
        p['chs']='250x100'
        p['chl']=chl.strip('|')
        p['chco']='00FF00|FF0000|FF9900,FF9900'
        p['chtt']=srctitle
        para='?'
        for e in p.keys():
            para=para+e+'='+p[e]+'&'
        para=para.strip('&')
        print para
        url=urlpre+para
        return url        
    def showchart_p(self,srcdata):
        sum=0.0
        chd='t:' 
        chl='' 
        for src in srcdata:
            sum=sum+src[1]
            chl=chl+src[0]+'|'
        dstdata=[]
        
        for src in srcdata:
            dstdata.append(src[1]/sum*360)  
        for dst in dstdata:
            chd=chd+str(dst)+','
            
        
        urlpre='http://chart.apis.google.com/chart'
        
        p={}
        p['cht']='p'
        p['chd']=chd.strip(',')
        p['chs']='250x100'
        p['chl']=chl.strip('|')
#        p['chtt']='Hello+World.'
        para='?'
        for e in p.keys():
            para=para+e+'='+p[e]+'&'
        para=para.strip('&')
        print para
        url=urlpre+para
        print url
        webbrowser.open(url)
if __name__ == '__main__':
    testdata={}
    testdata['>120']=1579
    testdata['<120']=1964
    testdata['other']=68
    c=Chart()
    c.showchart_p(testdata)
    pass